var app = getApp();
var c=require('../common.js');

Page({
  data: {
    showPayPwdInput: false,  //是否展示密码输入层
    pwdVal: '',  //输入的密码
    payFocus: true, //文本框焦点
  },
  onLoad: function (option) {
    var user_id = option.user_id;
    var value = option.value;
    this.setData({ user_id: user_id, value: value})
    this.showInputLayer();
  },
  /**
   * 显示支付密码输入层
   */
  showInputLayer: function () {
    this.setData({ showPayPwdInput: true, payFocus: true });
  },
  /**
   * 隐藏支付密码输入层
   */
  hidePayLayer: function () {
    var val = this.data.pwdVal;//密码
    var user_id = this.data.user_id;
    this.setData({ showPayPwdInput: false, payFocus: false, pwdVal: '' }, function () {
        c.ajax(
          app.url+'setpassword',
          { user_id: user_id, value: val},
          res=>{
            if (res.data==1){
                  wx.showToast({
                    title: '修改成功',
                    icon:'none'
                  })
                  setTimeout(function(){
                    wx.navigateTo({
                      url: '/pages/sendneedorder/sendneedorder?paystatys=1',
                      success: function(res) {},
                      fail: function(res) {},
                      complete: function(res) {},
                    })
                  },2000)
             }
          }
        )
    });

  },
  /**
   * 获取焦点
   */
  getFocus: function () {
    this.setData({ payFocus: true });
  },
  /**
   * 输入密码监听
   */
  inputPwd: function (e) {
    this.setData({ pwdVal: e.detail.value });

    if (e.detail.value.length >= 6) {
      this.hidePayLayer();
    }
  }
})